<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Irrlicht 3D Engine: irrMath.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Irrlicht 3D Engine
   
   </div>
   
  </td>
  
  
  
   
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="dynsections.js"></script>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('irr_math_8h.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">irrMath.h</div>  </div>
</div>
<div class="contents">
<a href="irr_math_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (C) 2002-2012 Nikolaus Gebhardt</span>
<a name="l00002"></a>00002 <span class="comment">// This file is part of the &quot;Irrlicht Engine&quot;.</span>
<a name="l00003"></a>00003 <span class="comment">// For conditions of distribution and use, see copyright notice in irrlicht.h</span>
<a name="l00004"></a>00004 
<a name="l00005"></a>00005 <span class="preprocessor">#ifndef __IRR_MATH_H_INCLUDED__</span>
<a name="l00006"></a>00006 <span class="preprocessor"></span><span class="preprocessor">#define __IRR_MATH_H_INCLUDED__</span>
<a name="l00007"></a>00007 <span class="preprocessor"></span>
<a name="l00008"></a>00008 <span class="preprocessor">#include &quot;<a class="code" href="_irr_compile_config_8h.html">IrrCompileConfig.h</a>&quot;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &quot;<a class="code" href="irr_types_8h.html">irrTypes.h</a>&quot;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;math.h&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;float.h&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;stdlib.h&gt;</span> <span class="comment">// for abs() etc.</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;limits.h&gt;</span> <span class="comment">// For INT_MAX / UINT_MAX</span>
<a name="l00014"></a>00014 
<a name="l00015"></a>00015 <span class="preprocessor">#if defined(_IRR_SOLARIS_PLATFORM_) || defined(__BORLANDC__) || defined (__BCPLUSPLUS__) || defined (_WIN32_WCE)</span>
<a name="l00016"></a>00016 <span class="preprocessor"></span><span class="preprocessor">    #define sqrtf(X) (irr::f32)sqrt((irr::f64)(X))</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span><span class="preprocessor">    #define sinf(X) (irr::f32)sin((irr::f64)(X))</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span><span class="preprocessor">    #define cosf(X) (irr::f32)cos((irr::f64)(X))</span>
<a name="l00019"></a>00019 <span class="preprocessor"></span><span class="preprocessor">    #define asinf(X) (irr::f32)asin((irr::f64)(X))</span>
<a name="l00020"></a>00020 <span class="preprocessor"></span><span class="preprocessor">    #define acosf(X) (irr::f32)acos((irr::f64)(X))</span>
<a name="l00021"></a>00021 <span class="preprocessor"></span><span class="preprocessor">    #define atan2f(X,Y) (irr::f32)atan2((irr::f64)(X),(irr::f64)(Y))</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">    #define ceilf(X) (irr::f32)ceil((irr::f64)(X))</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">    #define floorf(X) (irr::f32)floor((irr::f64)(X))</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">    #define powf(X,Y) (irr::f32)pow((irr::f64)(X),(irr::f64)(Y))</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">    #define fmodf(X,Y) (irr::f32)fmod((irr::f64)(X),(irr::f64)(Y))</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">    #define fabsf(X) (irr::f32)fabs((irr::f64)(X))</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">    #define logf(X) (irr::f32)log((irr::f64)(X))</span>
<a name="l00028"></a>00028 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span>
<a name="l00030"></a>00030 <span class="preprocessor">#ifndef FLT_MAX</span>
<a name="l00031"></a><a class="code" href="irr_math_8h.html#a7fbf1534f9e0f0bfdb86fb928902474c">00031</a> <span class="preprocessor"></span><span class="preprocessor">#define FLT_MAX 3.402823466E+38F</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span>
<a name="l00034"></a>00034 <span class="preprocessor">#ifndef FLT_MIN</span>
<a name="l00035"></a><a class="code" href="irr_math_8h.html#a890322b63a2fab56b8ff916c08368df6">00035</a> <span class="preprocessor"></span><span class="preprocessor">#define FLT_MIN 1.17549435e-38F</span>
<a name="l00036"></a>00036 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00037"></a>00037 <span class="preprocessor"></span>
<a name="l00038"></a>00038 <span class="keyword">namespace </span>irr
<a name="l00039"></a>00039 {
<a name="l00040"></a>00040 <span class="keyword">namespace </span>core
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042 
<a name="l00044"></a>00044 
<a name="l00045"></a><a class="code" href="namespaceirr_1_1core.html#aac9f99b6a999bdf25fec402c59e8342a">00045</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#aac9f99b6a999bdf25fec402c59e8342a" title="Rounding error constant often used when comparing f32 values.">ROUNDING_ERROR_S32</a> = 0;
<a name="l00046"></a>00046 <span class="preprocessor">#ifdef __IRR_HAS_S64</span>
<a name="l00047"></a><a class="code" href="namespaceirr_1_1core.html#acc1ea39594c72f97ff196e97c14ed6f3">00047</a> <span class="preprocessor"></span>    <span class="keyword">const</span> <a class="code" href="namespaceirr.html#abf54bd535f8d4dd996270e68c3ad8c08" title="64 bit signed variable.">s64</a> <a class="code" href="namespaceirr_1_1core.html#acc1ea39594c72f97ff196e97c14ed6f3">ROUNDING_ERROR_S64</a> = 0;
<a name="l00048"></a>00048 <span class="preprocessor">#endif</span>
<a name="l00049"></a><a class="code" href="namespaceirr_1_1core.html#a9514dd34463a30102ef8836915cf9c4c">00049</a> <span class="preprocessor"></span>    <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#a9514dd34463a30102ef8836915cf9c4c">ROUNDING_ERROR_f32</a> = 0.000001f;
<a name="l00050"></a><a class="code" href="namespaceirr_1_1core.html#a7b314c22d6804639cbcbce5231724f0b">00050</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> <a class="code" href="namespaceirr_1_1core.html#a7b314c22d6804639cbcbce5231724f0b">ROUNDING_ERROR_f64</a> = 0.00000001;
<a name="l00051"></a>00051 
<a name="l00052"></a>00052 <span class="preprocessor">#ifdef PI // make sure we don&#39;t collide with a define</span>
<a name="l00053"></a>00053 <span class="preprocessor"></span><span class="preprocessor">#undef PI</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00055"></a>00055 <span class="preprocessor"></span>
<a name="l00056"></a><a class="code" href="namespaceirr_1_1core.html#a26d877e2caf3e6f31c298a0417a0707e">00056</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#a26d877e2caf3e6f31c298a0417a0707e" title="Constant for PI.">PI</a>        = 3.14159265359f;
<a name="l00057"></a>00057 
<a name="l00059"></a><a class="code" href="namespaceirr_1_1core.html#ac97bfaa5b44703e61c23c91b88f3ec3a">00059</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#ac97bfaa5b44703e61c23c91b88f3ec3a" title="Constant for reciprocal of PI.">RECIPROCAL_PI</a> = 1.0f/<a class="code" href="namespaceirr_1_1core.html#a26d877e2caf3e6f31c298a0417a0707e" title="Constant for PI.">PI</a>;
<a name="l00060"></a>00060 
<a name="l00062"></a><a class="code" href="namespaceirr_1_1core.html#abeab884c4376c5740f6d916356e9baa3">00062</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#abeab884c4376c5740f6d916356e9baa3" title="Constant for half of PI.">HALF_PI</a>   = <a class="code" href="namespaceirr_1_1core.html#a26d877e2caf3e6f31c298a0417a0707e" title="Constant for PI.">PI</a>/2.0f;
<a name="l00063"></a>00063 
<a name="l00064"></a>00064 <span class="preprocessor">#ifdef PI64 // make sure we don&#39;t collide with a define</span>
<a name="l00065"></a>00065 <span class="preprocessor"></span><span class="preprocessor">#undef PI64</span>
<a name="l00066"></a>00066 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00067"></a>00067 <span class="preprocessor"></span>
<a name="l00068"></a><a class="code" href="namespaceirr_1_1core.html#a166af519140dc00cbd88684e835086f8">00068</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> <a class="code" href="namespaceirr_1_1core.html#a166af519140dc00cbd88684e835086f8" title="Constant for 64bit PI.">PI64</a>      = 3.1415926535897932384626433832795028841971693993751;
<a name="l00069"></a>00069 
<a name="l00071"></a><a class="code" href="namespaceirr_1_1core.html#ad3a2ddd6d772edb4d663d73fae5434e3">00071</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> <a class="code" href="namespaceirr_1_1core.html#ad3a2ddd6d772edb4d663d73fae5434e3" title="Constant for 64bit reciprocal of PI.">RECIPROCAL_PI64</a> = 1.0/<a class="code" href="namespaceirr_1_1core.html#a166af519140dc00cbd88684e835086f8" title="Constant for 64bit PI.">PI64</a>;
<a name="l00072"></a>00072 
<a name="l00074"></a><a class="code" href="namespaceirr_1_1core.html#a4b91e69e51a2e374aec940cba3869028">00074</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#a4b91e69e51a2e374aec940cba3869028" title="32bit Constant for converting from degrees to radians">DEGTORAD</a> = <a class="code" href="namespaceirr_1_1core.html#a26d877e2caf3e6f31c298a0417a0707e" title="Constant for PI.">PI</a> / 180.0f;
<a name="l00075"></a>00075 
<a name="l00077"></a><a class="code" href="namespaceirr_1_1core.html#ae3a530e0ef661960b7af89f07d817bd5">00077</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#ae3a530e0ef661960b7af89f07d817bd5" title="32bit constant for converting from radians to degrees (formally known as GRAD_PI)">RADTODEG</a>   = 180.0f / <a class="code" href="namespaceirr_1_1core.html#a26d877e2caf3e6f31c298a0417a0707e" title="Constant for PI.">PI</a>;
<a name="l00078"></a>00078 
<a name="l00080"></a><a class="code" href="namespaceirr_1_1core.html#a8e21b5969c8292857f7c9c5dcfd61c35">00080</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> <a class="code" href="namespaceirr_1_1core.html#a8e21b5969c8292857f7c9c5dcfd61c35" title="64bit constant for converting from degrees to radians (formally known as GRAD_PI2)">DEGTORAD64</a> = <a class="code" href="namespaceirr_1_1core.html#a166af519140dc00cbd88684e835086f8" title="Constant for 64bit PI.">PI64</a> / 180.0;
<a name="l00081"></a>00081 
<a name="l00083"></a><a class="code" href="namespaceirr_1_1core.html#ae7afeb48af12f5f5130cd179a644ec58">00083</a>     <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> <a class="code" href="namespaceirr_1_1core.html#ae7afeb48af12f5f5130cd179a644ec58" title="64bit constant for converting from radians to degrees">RADTODEG64</a> = 180.0 / <a class="code" href="namespaceirr_1_1core.html#a166af519140dc00cbd88684e835086f8" title="Constant for 64bit PI.">PI64</a>;
<a name="l00084"></a>00084 
<a name="l00086"></a>00086 
<a name="l00089"></a><a class="code" href="namespaceirr_1_1core.html#a8deb22ad77fb8ead3f6683bbf9ad3f67">00089</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#a8deb22ad77fb8ead3f6683bbf9ad3f67" title="Utility function to convert a radian value to degrees.">radToDeg</a>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> radians)
<a name="l00090"></a>00090     {
<a name="l00091"></a>00091         <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1core.html#ae3a530e0ef661960b7af89f07d817bd5" title="32bit constant for converting from radians to degrees (formally known as GRAD_PI)">RADTODEG</a> * radians;
<a name="l00092"></a>00092     }
<a name="l00093"></a>00093 
<a name="l00095"></a>00095 
<a name="l00098"></a><a class="code" href="namespaceirr_1_1core.html#aab39939b1518daee0967c368a3bf924a">00098</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> <a class="code" href="namespaceirr_1_1core.html#a8deb22ad77fb8ead3f6683bbf9ad3f67" title="Utility function to convert a radian value to degrees.">radToDeg</a>(<a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> radians)
<a name="l00099"></a>00099     {
<a name="l00100"></a>00100         <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1core.html#ae7afeb48af12f5f5130cd179a644ec58" title="64bit constant for converting from radians to degrees">RADTODEG64</a> * radians;
<a name="l00101"></a>00101     }
<a name="l00102"></a>00102 
<a name="l00104"></a>00104 
<a name="l00107"></a><a class="code" href="namespaceirr_1_1core.html#ad58b3d0e755a4f25ad19d5f5d4fb0280">00107</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#ad58b3d0e755a4f25ad19d5f5d4fb0280" title="Utility function to convert a degrees value to radians.">degToRad</a>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> degrees)
<a name="l00108"></a>00108     {
<a name="l00109"></a>00109         <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1core.html#a4b91e69e51a2e374aec940cba3869028" title="32bit Constant for converting from degrees to radians">DEGTORAD</a> * degrees;
<a name="l00110"></a>00110     }
<a name="l00111"></a>00111 
<a name="l00113"></a>00113 
<a name="l00116"></a><a class="code" href="namespaceirr_1_1core.html#a2def535b4f391ceb86ec0497cbb4bf80">00116</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> <a class="code" href="namespaceirr_1_1core.html#ad58b3d0e755a4f25ad19d5f5d4fb0280" title="Utility function to convert a degrees value to radians.">degToRad</a>(<a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> degrees)
<a name="l00117"></a>00117     {
<a name="l00118"></a>00118         <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1core.html#a8e21b5969c8292857f7c9c5dcfd61c35" title="64bit constant for converting from degrees to radians (formally known as GRAD_PI2)">DEGTORAD64</a> * degrees;
<a name="l00119"></a>00119     }
<a name="l00120"></a>00120 
<a name="l00122"></a>00122     <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00123"></a><a class="code" href="namespaceirr_1_1core.html#a9d34bfdbbe9c136b01ae04974572bc11">00123</a>     <span class="keyword">inline</span> <span class="keyword">const</span> T&amp; <a class="code" href="namespaceirr_1_1core.html#a9d34bfdbbe9c136b01ae04974572bc11" title="returns minimum of two values. Own implementation to get rid of the STL (VS6 problems)">min_</a>(<span class="keyword">const</span> T&amp; a, <span class="keyword">const</span> T&amp; b)
<a name="l00124"></a>00124     {
<a name="l00125"></a>00125         <span class="keywordflow">return</span> a &lt; b ? a : b;
<a name="l00126"></a>00126     }
<a name="l00127"></a>00127 
<a name="l00129"></a>00129     <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00130"></a><a class="code" href="namespaceirr_1_1core.html#a620f62b5ab8b484c16c0236ca7d65d33">00130</a>     <span class="keyword">inline</span> <span class="keyword">const</span> T&amp; <a class="code" href="namespaceirr_1_1core.html#a9d34bfdbbe9c136b01ae04974572bc11" title="returns minimum of two values. Own implementation to get rid of the STL (VS6 problems)">min_</a>(<span class="keyword">const</span> T&amp; a, <span class="keyword">const</span> T&amp; b, <span class="keyword">const</span> T&amp; c)
<a name="l00131"></a>00131     {
<a name="l00132"></a>00132         <span class="keywordflow">return</span> a &lt; b ? <a class="code" href="namespaceirr_1_1core.html#a9d34bfdbbe9c136b01ae04974572bc11" title="returns minimum of two values. Own implementation to get rid of the STL (VS6 problems)">min_</a>(a, c) : <a class="code" href="namespaceirr_1_1core.html#a9d34bfdbbe9c136b01ae04974572bc11" title="returns minimum of two values. Own implementation to get rid of the STL (VS6 problems)">min_</a>(b, c);
<a name="l00133"></a>00133     }
<a name="l00134"></a>00134 
<a name="l00136"></a>00136     <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00137"></a><a class="code" href="namespaceirr_1_1core.html#afca1ce7ac54e0c31a9047947f4c7319b">00137</a>     <span class="keyword">inline</span> <span class="keyword">const</span> T&amp; <a class="code" href="namespaceirr_1_1core.html#afca1ce7ac54e0c31a9047947f4c7319b" title="returns maximum of two values. Own implementation to get rid of the STL (VS6 problems)">max_</a>(<span class="keyword">const</span> T&amp; a, <span class="keyword">const</span> T&amp; b)
<a name="l00138"></a>00138     {
<a name="l00139"></a>00139         <span class="keywordflow">return</span> a &lt; b ? b : a;
<a name="l00140"></a>00140     }
<a name="l00141"></a>00141 
<a name="l00143"></a>00143     <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00144"></a><a class="code" href="namespaceirr_1_1core.html#ae279a231923e0c251ebfd171f03e689c">00144</a>     <span class="keyword">inline</span> <span class="keyword">const</span> T&amp; <a class="code" href="namespaceirr_1_1core.html#afca1ce7ac54e0c31a9047947f4c7319b" title="returns maximum of two values. Own implementation to get rid of the STL (VS6 problems)">max_</a>(<span class="keyword">const</span> T&amp; a, <span class="keyword">const</span> T&amp; b, <span class="keyword">const</span> T&amp; c)
<a name="l00145"></a>00145     {
<a name="l00146"></a>00146         <span class="keywordflow">return</span> a &lt; b ? <a class="code" href="namespaceirr_1_1core.html#afca1ce7ac54e0c31a9047947f4c7319b" title="returns maximum of two values. Own implementation to get rid of the STL (VS6 problems)">max_</a>(b, c) : <a class="code" href="namespaceirr_1_1core.html#afca1ce7ac54e0c31a9047947f4c7319b" title="returns maximum of two values. Own implementation to get rid of the STL (VS6 problems)">max_</a>(a, c);
<a name="l00147"></a>00147     }
<a name="l00148"></a>00148 
<a name="l00150"></a>00150     <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00151"></a><a class="code" href="namespaceirr_1_1core.html#a2cab2ba5899c9262ca29501ea7551c91">00151</a>     <span class="keyword">inline</span> T <a class="code" href="namespaceirr_1_1core.html#a2cab2ba5899c9262ca29501ea7551c91" title="returns abs of two values. Own implementation to get rid of STL (VS6 problems)">abs_</a>(<span class="keyword">const</span> T&amp; a)
<a name="l00152"></a>00152     {
<a name="l00153"></a>00153         <span class="keywordflow">return</span> a &lt; (T)0 ? -a : a;
<a name="l00154"></a>00154     }
<a name="l00155"></a>00155 
<a name="l00158"></a>00158     <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00159"></a><a class="code" href="namespaceirr_1_1core.html#ae2e6a5729b911d26565b508e8b8dae91">00159</a>     <span class="keyword">inline</span> T <a class="code" href="namespaceirr_1_1core.html#ae2e6a5729b911d26565b508e8b8dae91">lerp</a>(<span class="keyword">const</span> T&amp; a, <span class="keyword">const</span> T&amp; b, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> t)
<a name="l00160"></a>00160     {
<a name="l00161"></a>00161         <span class="keywordflow">return</span> (T)(a*(1.f-t)) + (b*t);
<a name="l00162"></a>00162     }
<a name="l00163"></a>00163 
<a name="l00165"></a>00165     <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00166"></a><a class="code" href="namespaceirr_1_1core.html#a6162f685b68f629e77336081d3316969">00166</a>     <span class="keyword">inline</span> <span class="keyword">const</span> T <a class="code" href="namespaceirr_1_1core.html#a6162f685b68f629e77336081d3316969" title="clamps a value between low and high">clamp</a> (<span class="keyword">const</span> T&amp; value, <span class="keyword">const</span> T&amp; low, <span class="keyword">const</span> T&amp; high)
<a name="l00167"></a>00167     {
<a name="l00168"></a>00168         <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1core.html#a9d34bfdbbe9c136b01ae04974572bc11" title="returns minimum of two values. Own implementation to get rid of the STL (VS6 problems)">min_</a> (<a class="code" href="namespaceirr_1_1core.html#afca1ce7ac54e0c31a9047947f4c7319b" title="returns maximum of two values. Own implementation to get rid of the STL (VS6 problems)">max_</a>(value,low), high);
<a name="l00169"></a>00169     }
<a name="l00170"></a>00170 
<a name="l00172"></a>00172     <span class="comment">// Note: We use the same trick as boost and use two template arguments to</span>
<a name="l00173"></a>00173     <span class="comment">// avoid ambiguity when swapping objects of an Irrlicht type that has not</span>
<a name="l00174"></a>00174     <span class="comment">// it&#39;s own swap overload. Otherwise we get conflicts with some compilers</span>
<a name="l00175"></a>00175     <span class="comment">// in combination with stl.</span>
<a name="l00176"></a>00176     <span class="keyword">template</span> &lt;<span class="keyword">class</span> T1, <span class="keyword">class</span> T2&gt;
<a name="l00177"></a><a class="code" href="namespaceirr_1_1core.html#ab565e5d5112b21ff9b96a0ca0c9b89ad">00177</a>     <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="namespaceirr_1_1core.html#ab565e5d5112b21ff9b96a0ca0c9b89ad" title="swaps the content of the passed parameters">swap</a>(T1&amp; a, T2&amp; b)
<a name="l00178"></a>00178     {
<a name="l00179"></a>00179         T1 c(a);
<a name="l00180"></a>00180         a = b;
<a name="l00181"></a>00181         b = c;
<a name="l00182"></a>00182     }
<a name="l00183"></a>00183 
<a name="l00185"></a><a class="code" href="namespaceirr_1_1core.html#abf9b9b140cc365908ea4c8c47451e4e3">00185</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#abf9b9b140cc365908ea4c8c47451e4e3" title="returns if a equals b, taking possible rounding errors into account">equals</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> b, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> tolerance = <a class="code" href="namespaceirr_1_1core.html#a7b314c22d6804639cbcbce5231724f0b">ROUNDING_ERROR_f64</a>)
<a name="l00186"></a>00186     {
<a name="l00187"></a>00187         <span class="keywordflow">return</span> (a + tolerance &gt;= b) &amp;&amp; (a - tolerance &lt;= b);
<a name="l00188"></a>00188     }
<a name="l00189"></a>00189 
<a name="l00191"></a><a class="code" href="namespaceirr_1_1core.html#ae9c63fd2065e6afd30b4537166706ddf">00191</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#abf9b9b140cc365908ea4c8c47451e4e3" title="returns if a equals b, taking possible rounding errors into account">equals</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> b, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> tolerance = <a class="code" href="namespaceirr_1_1core.html#a9514dd34463a30102ef8836915cf9c4c">ROUNDING_ERROR_f32</a>)
<a name="l00192"></a>00192     {
<a name="l00193"></a>00193         <span class="keywordflow">return</span> (a + tolerance &gt;= b) &amp;&amp; (a - tolerance &lt;= b);
<a name="l00194"></a>00194     }
<a name="l00195"></a>00195 
<a name="l00196"></a><a class="code" href="unionirr_1_1core_1_1_float_int_union32.html">00196</a>     <span class="keyword">union </span><a class="code" href="unionirr_1_1core_1_1_float_int_union32.html">FloatIntUnion32</a>
<a name="l00197"></a>00197     {
<a name="l00198"></a><a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a8bb52272b7efd87afba959ae50365d24">00198</a>         <a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a8bb52272b7efd87afba959ae50365d24">FloatIntUnion32</a>(<span class="keywordtype">float</span> f1 = 0.0<a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a6be8ea1e57c1fa1824799c470d08af98">f</a>) : <a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a6be8ea1e57c1fa1824799c470d08af98">f</a>(f1) {}
<a name="l00199"></a>00199         <span class="comment">// Portable sign-extraction</span>
<a name="l00200"></a><a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a24af76290e16126c533f6b76391372b3">00200</a>         <span class="keywordtype">bool</span> <a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a24af76290e16126c533f6b76391372b3">sign</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> (<a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a79c3131fd06e80a7ca80b9c0201c60fb">i</a> &gt;&gt; 31) != 0; }
<a name="l00201"></a>00201 
<a name="l00202"></a><a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a79c3131fd06e80a7ca80b9c0201c60fb">00202</a>         <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">irr::s32</a> <a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a79c3131fd06e80a7ca80b9c0201c60fb">i</a>;
<a name="l00203"></a><a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a6be8ea1e57c1fa1824799c470d08af98">00203</a>         <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">irr::f32</a> <a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a6be8ea1e57c1fa1824799c470d08af98">f</a>;
<a name="l00204"></a>00204     };
<a name="l00205"></a>00205 
<a name="l00207"></a>00207     <span class="comment">//\result true when numbers have a ULP &lt;= maxUlpDiff AND have the same sign.</span>
<a name="l00208"></a><a class="code" href="namespaceirr_1_1core.html#a730a85283e04b33debcf3b755e5b7603">00208</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#a730a85283e04b33debcf3b755e5b7603" title="We compare the difference in ULP&#39;s (spacing between floating-point numbers, aka ULP=1 means there exi...">equalsByUlp</a>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> a, <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> b, <span class="keywordtype">int</span> maxUlpDiff)
<a name="l00209"></a>00209     {
<a name="l00210"></a>00210         <span class="comment">// Based on the ideas and code from Bruce Dawson on</span>
<a name="l00211"></a>00211         <span class="comment">// http://www.altdevblogaday.com/2012/02/22/comparing-floating-point-numbers-2012-edition/</span>
<a name="l00212"></a>00212         <span class="comment">// When floats are interpreted as integers the two nearest possible float numbers differ just</span>
<a name="l00213"></a>00213         <span class="comment">// by one integer number. Also works the other way round, an integer of 1 interpreted as float</span>
<a name="l00214"></a>00214         <span class="comment">// is for example the smallest possible float number.</span>
<a name="l00215"></a>00215 
<a name="l00216"></a>00216         <a class="code" href="unionirr_1_1core_1_1_float_int_union32.html">FloatIntUnion32</a> fa(a);
<a name="l00217"></a>00217         <a class="code" href="unionirr_1_1core_1_1_float_int_union32.html">FloatIntUnion32</a> fb(b);
<a name="l00218"></a>00218 
<a name="l00219"></a>00219         <span class="comment">// Different signs, we could maybe get difference to 0, but so close to 0 using epsilons is better.</span>
<a name="l00220"></a>00220         <span class="keywordflow">if</span> ( fa.<a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a24af76290e16126c533f6b76391372b3">sign</a>() != fb.<a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a24af76290e16126c533f6b76391372b3">sign</a>() )
<a name="l00221"></a>00221         {
<a name="l00222"></a>00222             <span class="comment">// Check for equality to make sure +0==-0</span>
<a name="l00223"></a>00223             <span class="keywordflow">if</span> (fa.<a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a79c3131fd06e80a7ca80b9c0201c60fb">i</a> == fb.<a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a79c3131fd06e80a7ca80b9c0201c60fb">i</a>)
<a name="l00224"></a>00224                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00225"></a>00225             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00226"></a>00226         }
<a name="l00227"></a>00227 
<a name="l00228"></a>00228         <span class="comment">// Find the difference in ULPs.</span>
<a name="l00229"></a>00229         <span class="keywordtype">int</span> ulpsDiff = <a class="code" href="namespaceirr_1_1core.html#a2cab2ba5899c9262ca29501ea7551c91" title="returns abs of two values. Own implementation to get rid of STL (VS6 problems)">abs_</a>(fa.<a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a79c3131fd06e80a7ca80b9c0201c60fb">i</a>- fb.<a class="code" href="unionirr_1_1core_1_1_float_int_union32.html#a79c3131fd06e80a7ca80b9c0201c60fb">i</a>);
<a name="l00230"></a>00230         <span class="keywordflow">if</span> (ulpsDiff &lt;= maxUlpDiff)
<a name="l00231"></a>00231             <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00232"></a>00232 
<a name="l00233"></a>00233         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00234"></a>00234     }
<a name="l00235"></a>00235 
<a name="l00236"></a>00236 <span class="preprocessor">#if 0</span>
<a name="l00237"></a>00237 <span class="preprocessor"></span>
<a name="l00238"></a>00238     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#abf9b9b140cc365908ea4c8c47451e4e3" title="returns if a equals b, taking possible rounding errors into account">equals</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> b)
<a name="l00239"></a>00239     {
<a name="l00240"></a>00240         <span class="keywordflow">return</span> (a == b);
<a name="l00241"></a>00241     }
<a name="l00242"></a>00242 
<a name="l00244"></a>00244     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#abf9b9b140cc365908ea4c8c47451e4e3" title="returns if a equals b, taking possible rounding errors into account">equals</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> b)
<a name="l00245"></a>00245     {
<a name="l00246"></a>00246         <span class="keywordflow">return</span> (a == b);
<a name="l00247"></a>00247     }
<a name="l00248"></a>00248 <span class="preprocessor">#endif</span>
<a name="l00249"></a>00249 <span class="preprocessor"></span>
<a name="l00250"></a><a class="code" href="namespaceirr_1_1core.html#afe4784d5bf091acce7777c40c4010ff8">00250</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#abf9b9b140cc365908ea4c8c47451e4e3" title="returns if a equals b, taking possible rounding errors into account">equals</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> b, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> tolerance = <a class="code" href="namespaceirr_1_1core.html#aac9f99b6a999bdf25fec402c59e8342a" title="Rounding error constant often used when comparing f32 values.">ROUNDING_ERROR_S32</a>)
<a name="l00251"></a>00251     {
<a name="l00252"></a>00252         <span class="keywordflow">return</span> (a + tolerance &gt;= b) &amp;&amp; (a - tolerance &lt;= b);
<a name="l00253"></a>00253     }
<a name="l00254"></a>00254 
<a name="l00256"></a><a class="code" href="namespaceirr_1_1core.html#a9a54aa08fdc2119258ad8dfa44f8dadf">00256</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#abf9b9b140cc365908ea4c8c47451e4e3" title="returns if a equals b, taking possible rounding errors into account">equals</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> b, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> tolerance = <a class="code" href="namespaceirr_1_1core.html#aac9f99b6a999bdf25fec402c59e8342a" title="Rounding error constant often used when comparing f32 values.">ROUNDING_ERROR_S32</a>)
<a name="l00257"></a>00257     {
<a name="l00258"></a>00258         <span class="keywordflow">return</span> (a + tolerance &gt;= b) &amp;&amp; (a - tolerance &lt;= b);
<a name="l00259"></a>00259     }
<a name="l00260"></a>00260 
<a name="l00261"></a>00261 <span class="preprocessor">#ifdef __IRR_HAS_S64</span>
<a name="l00262"></a>00262 <span class="preprocessor"></span>
<a name="l00263"></a><a class="code" href="namespaceirr_1_1core.html#a7928ce8e86ff93d918b0c144efab7b47">00263</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#abf9b9b140cc365908ea4c8c47451e4e3" title="returns if a equals b, taking possible rounding errors into account">equals</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#abf54bd535f8d4dd996270e68c3ad8c08" title="64 bit signed variable.">s64</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#abf54bd535f8d4dd996270e68c3ad8c08" title="64 bit signed variable.">s64</a> b, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#abf54bd535f8d4dd996270e68c3ad8c08" title="64 bit signed variable.">s64</a> tolerance = <a class="code" href="namespaceirr_1_1core.html#acc1ea39594c72f97ff196e97c14ed6f3">ROUNDING_ERROR_S64</a>)
<a name="l00264"></a>00264     {
<a name="l00265"></a>00265         <span class="keywordflow">return</span> (a + tolerance &gt;= b) &amp;&amp; (a - tolerance &lt;= b);
<a name="l00266"></a>00266     }
<a name="l00267"></a>00267 <span class="preprocessor">#endif</span>
<a name="l00268"></a>00268 <span class="preprocessor"></span>
<a name="l00270"></a><a class="code" href="namespaceirr_1_1core.html#afc24e6ba26469ec7ca7001ed272dc3b2">00270</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#afc24e6ba26469ec7ca7001ed272dc3b2" title="returns if a equals zero, taking rounding errors into account">iszero</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> tolerance = <a class="code" href="namespaceirr_1_1core.html#a7b314c22d6804639cbcbce5231724f0b">ROUNDING_ERROR_f64</a>)
<a name="l00271"></a>00271     {
<a name="l00272"></a>00272         <span class="keywordflow">return</span> fabs(a) &lt;= tolerance;
<a name="l00273"></a>00273     }
<a name="l00274"></a>00274 
<a name="l00276"></a><a class="code" href="namespaceirr_1_1core.html#aaf94a81169679083a48f9f9e6dced684">00276</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#afc24e6ba26469ec7ca7001ed272dc3b2" title="returns if a equals zero, taking rounding errors into account">iszero</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> tolerance = <a class="code" href="namespaceirr_1_1core.html#a9514dd34463a30102ef8836915cf9c4c">ROUNDING_ERROR_f32</a>)
<a name="l00277"></a>00277     {
<a name="l00278"></a>00278         <span class="keywordflow">return</span> fabsf(a) &lt;= tolerance;
<a name="l00279"></a>00279     }
<a name="l00280"></a>00280 
<a name="l00282"></a><a class="code" href="namespaceirr_1_1core.html#a6e179d6dd92b81607f0539329dc2410a">00282</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#a6e179d6dd92b81607f0539329dc2410a" title="returns if a equals not zero, taking rounding errors into account">isnotzero</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> tolerance = <a class="code" href="namespaceirr_1_1core.html#a9514dd34463a30102ef8836915cf9c4c">ROUNDING_ERROR_f32</a>)
<a name="l00283"></a>00283     {
<a name="l00284"></a>00284         <span class="keywordflow">return</span> fabsf(a) &gt; tolerance;
<a name="l00285"></a>00285     }
<a name="l00286"></a>00286 
<a name="l00288"></a><a class="code" href="namespaceirr_1_1core.html#a3842b13dc7bd40f068cc8f7fd91bcfa5">00288</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#afc24e6ba26469ec7ca7001ed272dc3b2" title="returns if a equals zero, taking rounding errors into account">iszero</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> tolerance = 0)
<a name="l00289"></a>00289     {
<a name="l00290"></a>00290         <span class="keywordflow">return</span> ( a &amp; 0x7ffffff ) &lt;= tolerance;
<a name="l00291"></a>00291     }
<a name="l00292"></a>00292 
<a name="l00294"></a><a class="code" href="namespaceirr_1_1core.html#afa64d4495f986ec0fa840e61cba45c68">00294</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#afc24e6ba26469ec7ca7001ed272dc3b2" title="returns if a equals zero, taking rounding errors into account">iszero</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> tolerance = 0)
<a name="l00295"></a>00295     {
<a name="l00296"></a>00296         <span class="keywordflow">return</span> a &lt;= tolerance;
<a name="l00297"></a>00297     }
<a name="l00298"></a>00298 
<a name="l00299"></a>00299 <span class="preprocessor">#ifdef __IRR_HAS_S64</span>
<a name="l00300"></a>00300 <span class="preprocessor"></span>
<a name="l00301"></a><a class="code" href="namespaceirr_1_1core.html#a418bebacbef432fcf909e8f3d9b8368d">00301</a>     <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#afc24e6ba26469ec7ca7001ed272dc3b2" title="returns if a equals zero, taking rounding errors into account">iszero</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#abf54bd535f8d4dd996270e68c3ad8c08" title="64 bit signed variable.">s64</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#abf54bd535f8d4dd996270e68c3ad8c08" title="64 bit signed variable.">s64</a> tolerance = 0)
<a name="l00302"></a>00302     {
<a name="l00303"></a>00303         <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1core.html#a2cab2ba5899c9262ca29501ea7551c91" title="returns abs of two values. Own implementation to get rid of STL (VS6 problems)">abs_</a>(a) &lt;= tolerance;
<a name="l00304"></a>00304     }
<a name="l00305"></a>00305 <span class="preprocessor">#endif</span>
<a name="l00306"></a>00306 <span class="preprocessor"></span>
<a name="l00307"></a><a class="code" href="namespaceirr_1_1core.html#aa0d9ebcfeca532643e76cf58b98daca1">00307</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#aa0d9ebcfeca532643e76cf58b98daca1">s32_min</a>(<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> a, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> b)
<a name="l00308"></a>00308     {
<a name="l00309"></a>00309         <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> mask = (a - b) &gt;&gt; 31;
<a name="l00310"></a>00310         <span class="keywordflow">return</span> (a &amp; mask) | (b &amp; ~mask);
<a name="l00311"></a>00311     }
<a name="l00312"></a>00312 
<a name="l00313"></a><a class="code" href="namespaceirr_1_1core.html#a3adbc0ee7f78051eb2a35511fe90bd2d">00313</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#a3adbc0ee7f78051eb2a35511fe90bd2d">s32_max</a>(<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> a, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> b)
<a name="l00314"></a>00314     {
<a name="l00315"></a>00315         <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> mask = (a - b) &gt;&gt; 31;
<a name="l00316"></a>00316         <span class="keywordflow">return</span> (b &amp; mask) | (a &amp; ~mask);
<a name="l00317"></a>00317     }
<a name="l00318"></a>00318 
<a name="l00319"></a><a class="code" href="namespaceirr_1_1core.html#aa7828c932a36c62a67fd0f2b972d8b21">00319</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#aa7828c932a36c62a67fd0f2b972d8b21">s32_clamp</a> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> value, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> low, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> high)
<a name="l00320"></a>00320     {
<a name="l00321"></a>00321         <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1core.html#aa0d9ebcfeca532643e76cf58b98daca1">s32_min</a>(<a class="code" href="namespaceirr_1_1core.html#a3adbc0ee7f78051eb2a35511fe90bd2d">s32_max</a>(value,low), high);
<a name="l00322"></a>00322     }
<a name="l00323"></a>00323 
<a name="l00324"></a>00324     <span class="comment">/*</span>
<a name="l00325"></a>00325 <span class="comment">        float IEEE-754 bit represenation</span>
<a name="l00326"></a>00326 <span class="comment"></span>
<a name="l00327"></a>00327 <span class="comment">        0      0x00000000</span>
<a name="l00328"></a>00328 <span class="comment">        1.0    0x3f800000</span>
<a name="l00329"></a>00329 <span class="comment">        0.5    0x3f000000</span>
<a name="l00330"></a>00330 <span class="comment">        3      0x40400000</span>
<a name="l00331"></a>00331 <span class="comment">        +inf   0x7f800000</span>
<a name="l00332"></a>00332 <span class="comment">        -inf   0xff800000</span>
<a name="l00333"></a>00333 <span class="comment">        +NaN   0x7fc00000 or 0x7ff00000</span>
<a name="l00334"></a>00334 <span class="comment">        in general: number = (sign ? -1:1) * 2^(exponent) * 1.(mantissa bits)</span>
<a name="l00335"></a>00335 <span class="comment">    */</span>
<a name="l00336"></a>00336 
<a name="l00337"></a><a class="code" href="unionirr_1_1core_1_1inttofloat.html#a87651356c7436ac7755e85189412f75a">00337</a>     <span class="keyword">typedef</span> <span class="keyword">union </span>{ <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> <a class="code" href="unionirr_1_1core_1_1inttofloat.html#a87651356c7436ac7755e85189412f75a">u</a>; <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> s; <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> f; } <a class="code" href="unionirr_1_1core_1_1inttofloat.html">inttofloat</a>;
<a name="l00338"></a>00338 
<a name="l00339"></a><a class="code" href="irr_math_8h.html#afc4f1a86cb2a79c560b29ee5edd0f94d">00339</a> <span class="preprocessor">    #define F32_AS_S32(f)       (*((s32 *) &amp;(f)))</span>
<a name="l00340"></a><a class="code" href="irr_math_8h.html#afdeb4b30296d2b1dccec72427bdb39f2">00340</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_AS_U32(f)       (*((u32 *) &amp;(f)))</span>
<a name="l00341"></a><a class="code" href="irr_math_8h.html#ab5498fea750901e87dfeca4e27425f16">00341</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_AS_U32_POINTER(f)   ( ((u32 *) &amp;(f)))</span>
<a name="l00342"></a>00342 <span class="preprocessor"></span>
<a name="l00343"></a><a class="code" href="irr_math_8h.html#aff2ace8fbd4b2ee6833ae0ed8dd9469a">00343</a> <span class="preprocessor">    #define F32_VALUE_0     0x00000000</span>
<a name="l00344"></a><a class="code" href="irr_math_8h.html#a93465b810662025b38f42244b100fc2e">00344</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_VALUE_1     0x3f800000</span>
<a name="l00345"></a><a class="code" href="irr_math_8h.html#a58566d4b084b3c9740b3215cf7a607bb">00345</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_SIGN_BIT        0x80000000U</span>
<a name="l00346"></a><a class="code" href="irr_math_8h.html#a94abc82f2a2794c8331c9dad9a06958b">00346</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_EXPON_MANTISSA  0x7FFFFFFFU</span>
<a name="l00347"></a>00347 <span class="preprocessor"></span>
<a name="l00350"></a>00350 <span class="preprocessor">#ifdef IRRLICHT_FAST_MATH</span>
<a name="l00351"></a>00351 <span class="preprocessor"></span><span class="preprocessor">    #define IR(x)                           ((u32&amp;)(x))</span>
<a name="l00352"></a>00352 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00353"></a><a class="code" href="namespaceirr_1_1core.html#aff42ea2c4d80cb7b45b71d1f63c6a226">00353</a> <span class="preprocessor"></span>    <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> <a class="code" href="namespaceirr_1_1core.html#aff42ea2c4d80cb7b45b71d1f63c6a226">IR</a>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> x) {<a class="code" href="unionirr_1_1core_1_1inttofloat.html">inttofloat</a> tmp; tmp.<a class="code" href="unionirr_1_1core_1_1inttofloat.html#ab0dd36fa35cbb368602fa0d18b2d9788">f</a>=x; <span class="keywordflow">return</span> tmp.<a class="code" href="unionirr_1_1core_1_1inttofloat.html#a87651356c7436ac7755e85189412f75a">u</a>;}
<a name="l00354"></a>00354 <span class="preprocessor">#endif</span>
<a name="l00355"></a>00355 <span class="preprocessor"></span>
<a name="l00357"></a><a class="code" href="irr_math_8h.html#aa854d8430e0acc31adb1ddb3647f6534">00357</a> <span class="preprocessor">    #define AIR(x)              (IR(x)&amp;0x7fffffff)</span>
<a name="l00358"></a>00358 <span class="preprocessor"></span>
<a name="l00360"></a>00360 <span class="preprocessor">#ifdef IRRLICHT_FAST_MATH</span>
<a name="l00361"></a>00361 <span class="preprocessor"></span><span class="preprocessor">    #define FR(x)                           ((f32&amp;)(x))</span>
<a name="l00362"></a>00362 <span class="preprocessor"></span><span class="preprocessor">#else</span>
<a name="l00363"></a><a class="code" href="namespaceirr_1_1core.html#ae0940bd4032e5f10cf83b460f73571a3">00363</a> <span class="preprocessor"></span>    <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#ae0940bd4032e5f10cf83b460f73571a3" title="Floating-point representation of an integer value.">FR</a>(<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> x) {<a class="code" href="unionirr_1_1core_1_1inttofloat.html">inttofloat</a> tmp; tmp.<a class="code" href="unionirr_1_1core_1_1inttofloat.html#a87651356c7436ac7755e85189412f75a">u</a>=x; <span class="keywordflow">return</span> tmp.<a class="code" href="unionirr_1_1core_1_1inttofloat.html#ab0dd36fa35cbb368602fa0d18b2d9788">f</a>;}
<a name="l00364"></a><a class="code" href="namespaceirr_1_1core.html#a10bf7ddf910b7feac9a36fd141a9f5ba">00364</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#ae0940bd4032e5f10cf83b460f73571a3" title="Floating-point representation of an integer value.">FR</a>(<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> x) {<a class="code" href="unionirr_1_1core_1_1inttofloat.html">inttofloat</a> tmp; tmp.<a class="code" href="unionirr_1_1core_1_1inttofloat.html#a1adc8b3417ac325bd9695c0cbb6c043e">s</a>=x; <span class="keywordflow">return</span> tmp.<a class="code" href="unionirr_1_1core_1_1inttofloat.html#ab0dd36fa35cbb368602fa0d18b2d9788">f</a>;}
<a name="l00365"></a>00365 <span class="preprocessor">#endif</span>
<a name="l00366"></a>00366 <span class="preprocessor"></span>
<a name="l00368"></a><a class="code" href="irr_math_8h.html#a3ec4980c07f6b510c61230356e014d24">00368</a> <span class="preprocessor">    #define IEEE_1_0            0x3f800000</span>
<a name="l00369"></a>00369 <span class="preprocessor"></span>
<a name="l00370"></a><a class="code" href="irr_math_8h.html#a2b311316554140ac181c31d86f4f3786">00370</a> <span class="preprocessor">    #define IEEE_255_0          0x437f0000</span>
<a name="l00371"></a>00371 <span class="preprocessor"></span>
<a name="l00372"></a>00372 <span class="preprocessor">#ifdef IRRLICHT_FAST_MATH</span>
<a name="l00373"></a>00373 <span class="preprocessor"></span><span class="preprocessor">    #define F32_LOWER_0(f)      (F32_AS_U32(f) &gt;  F32_SIGN_BIT)</span>
<a name="l00374"></a>00374 <span class="preprocessor"></span><span class="preprocessor">    #define F32_LOWER_EQUAL_0(f)    (F32_AS_S32(f) &lt;= F32_VALUE_0)</span>
<a name="l00375"></a>00375 <span class="preprocessor"></span><span class="preprocessor">    #define F32_GREATER_0(f)    (F32_AS_S32(f) &gt;  F32_VALUE_0)</span>
<a name="l00376"></a>00376 <span class="preprocessor"></span><span class="preprocessor">    #define F32_GREATER_EQUAL_0(f)  (F32_AS_U32(f) &lt;= F32_SIGN_BIT)</span>
<a name="l00377"></a>00377 <span class="preprocessor"></span><span class="preprocessor">    #define F32_EQUAL_1(f)      (F32_AS_U32(f) == F32_VALUE_1)</span>
<a name="l00378"></a>00378 <span class="preprocessor"></span><span class="preprocessor">    #define F32_EQUAL_0(f)      ( (F32_AS_U32(f) &amp; F32_EXPON_MANTISSA ) == F32_VALUE_0)</span>
<a name="l00379"></a>00379 <span class="preprocessor"></span>
<a name="l00380"></a>00380     <span class="comment">// only same sign</span>
<a name="l00381"></a>00381 <span class="preprocessor">    #define F32_A_GREATER_B(a,b)    (F32_AS_S32((a)) &gt; F32_AS_S32((b)))</span>
<a name="l00382"></a>00382 <span class="preprocessor"></span>
<a name="l00383"></a>00383 <span class="preprocessor">#else</span>
<a name="l00384"></a>00384 <span class="preprocessor"></span>
<a name="l00385"></a><a class="code" href="irr_math_8h.html#aa86a7d03858f88ebbf9e36592583ced6">00385</a> <span class="preprocessor">    #define F32_LOWER_0(n)      ((n) &lt;  0.0f)</span>
<a name="l00386"></a><a class="code" href="irr_math_8h.html#a26bc42a9cc1fc775bc588052c32ff9a0">00386</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_LOWER_EQUAL_0(n)    ((n) &lt;= 0.0f)</span>
<a name="l00387"></a><a class="code" href="irr_math_8h.html#a2fdc9e94ce29e1866ddf64e5903d43a1">00387</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_GREATER_0(n)    ((n) &gt;  0.0f)</span>
<a name="l00388"></a><a class="code" href="irr_math_8h.html#a407afe61680cc405bbe04922d36423af">00388</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_GREATER_EQUAL_0(n)  ((n) &gt;= 0.0f)</span>
<a name="l00389"></a><a class="code" href="irr_math_8h.html#ae907baf637203996fb3187581c2def80">00389</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_EQUAL_1(n)      ((n) == 1.0f)</span>
<a name="l00390"></a><a class="code" href="irr_math_8h.html#a3c82a09fb606a67c19514b534d364d6c">00390</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_EQUAL_0(n)      ((n) == 0.0f)</span>
<a name="l00391"></a><a class="code" href="irr_math_8h.html#ab4092d1d22af18e03372117e347b633c">00391</a> <span class="preprocessor"></span><span class="preprocessor">    #define F32_A_GREATER_B(a,b)    ((a) &gt; (b))</span>
<a name="l00392"></a>00392 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00393"></a>00393 <span class="preprocessor"></span>
<a name="l00394"></a>00394 
<a name="l00395"></a>00395 <span class="preprocessor">#ifndef REALINLINE</span>
<a name="l00396"></a>00396 <span class="preprocessor"></span><span class="preprocessor">    #ifdef _MSC_VER</span>
<a name="l00397"></a>00397 <span class="preprocessor"></span><span class="preprocessor">        #define REALINLINE __forceinline</span>
<a name="l00398"></a>00398 <span class="preprocessor"></span><span class="preprocessor">    #else</span>
<a name="l00399"></a><a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">00399</a> <span class="preprocessor"></span><span class="preprocessor">        #define REALINLINE inline</span>
<a name="l00400"></a>00400 <span class="preprocessor"></span><span class="preprocessor">    #endif</span>
<a name="l00401"></a>00401 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00402"></a>00402 <span class="preprocessor"></span>
<a name="l00403"></a>00403 <span class="preprocessor">#if defined(__BORLANDC__) || defined (__BCPLUSPLUS__)</span>
<a name="l00404"></a>00404 <span class="preprocessor"></span>
<a name="l00405"></a>00405     <span class="comment">// 8-bit bools in borland builder</span>
<a name="l00406"></a>00406 
<a name="l00408"></a>00408     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> <a class="code" href="namespaceirr_1_1core.html#ad6426246733e5dc16713f43352d85cdb" title="conditional set based on mask and arithmetic shift">if_c_a_else_b</a> ( <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a9395eaea339bcb546b319e9c96bf7410" title="8 bit character variable.">c8</a> condition, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> b )
<a name="l00409"></a>00409     {
<a name="l00410"></a>00410         <span class="keywordflow">return</span> ( ( -condition &gt;&gt; 7 ) &amp; ( a ^ b ) ) ^ b;
<a name="l00411"></a>00411     }
<a name="l00412"></a>00412 
<a name="l00414"></a>00414     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> <a class="code" href="namespaceirr_1_1core.html#af19c13d0084052f12357308c0cd83005" title="conditional set based on mask and arithmetic shift">if_c_a_else_0</a> ( <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a9395eaea339bcb546b319e9c96bf7410" title="8 bit character variable.">c8</a> condition, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> a )
<a name="l00415"></a>00415     {
<a name="l00416"></a>00416         <span class="keywordflow">return</span> ( -condition &gt;&gt; 31 ) &amp; a;
<a name="l00417"></a>00417     }
<a name="l00418"></a>00418 <span class="preprocessor">#else</span>
<a name="l00419"></a>00419 <span class="preprocessor"></span>
<a name="l00421"></a><a class="code" href="namespaceirr_1_1core.html#ad6426246733e5dc16713f43352d85cdb">00421</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> <a class="code" href="namespaceirr_1_1core.html#ad6426246733e5dc16713f43352d85cdb" title="conditional set based on mask and arithmetic shift">if_c_a_else_b</a> ( <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> condition, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> b )
<a name="l00422"></a>00422     {
<a name="l00423"></a>00423         <span class="keywordflow">return</span> ( ( -condition &gt;&gt; 31 ) &amp; ( a ^ b ) ) ^ b;
<a name="l00424"></a>00424     }
<a name="l00425"></a>00425 
<a name="l00427"></a><a class="code" href="namespaceirr_1_1core.html#af1ec8eb919fdb81c259920cce4004329">00427</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#ae9f8ec82692ad3b83c21f555bfa70bcc" title="16 bit unsigned variable.">u16</a> <a class="code" href="namespaceirr_1_1core.html#ad6426246733e5dc16713f43352d85cdb" title="conditional set based on mask and arithmetic shift">if_c_a_else_b</a> ( <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a43ace0af066371ac0862bac3f7314220" title="16 bit signed variable.">s16</a> condition, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ae9f8ec82692ad3b83c21f555bfa70bcc" title="16 bit unsigned variable.">u16</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ae9f8ec82692ad3b83c21f555bfa70bcc" title="16 bit unsigned variable.">u16</a> b )
<a name="l00428"></a>00428     {
<a name="l00429"></a>00429         <span class="keywordflow">return</span> ( ( -condition &gt;&gt; 15 ) &amp; ( a ^ b ) ) ^ b;
<a name="l00430"></a>00430     }
<a name="l00431"></a>00431 
<a name="l00433"></a><a class="code" href="namespaceirr_1_1core.html#af19c13d0084052f12357308c0cd83005">00433</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> <a class="code" href="namespaceirr_1_1core.html#af19c13d0084052f12357308c0cd83005" title="conditional set based on mask and arithmetic shift">if_c_a_else_0</a> ( <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> condition, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> a )
<a name="l00434"></a>00434     {
<a name="l00435"></a>00435         <span class="keywordflow">return</span> ( -condition &gt;&gt; 31 ) &amp; a;
<a name="l00436"></a>00436     }
<a name="l00437"></a>00437 <span class="preprocessor">#endif</span>
<a name="l00438"></a>00438 <span class="preprocessor"></span>
<a name="l00439"></a>00439     <span class="comment">/*</span>
<a name="l00440"></a>00440 <span class="comment">        if (condition) state |= m; else state &amp;= ~m;</span>
<a name="l00441"></a>00441 <span class="comment">    */</span>
<a name="l00442"></a><a class="code" href="namespaceirr_1_1core.html#a628051738e8873b91b064e6014024f41">00442</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <span class="keywordtype">void</span> <a class="code" href="namespaceirr_1_1core.html#a628051738e8873b91b064e6014024f41">setbit_cond</a> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> &amp;state, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> condition, <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> mask )
<a name="l00443"></a>00443     {
<a name="l00444"></a>00444         <span class="comment">// 0, or any postive to mask</span>
<a name="l00445"></a>00445         <span class="comment">//s32 conmask = -condition &gt;&gt; 31;</span>
<a name="l00446"></a>00446         state ^= ( ( -condition &gt;&gt; 31 ) ^ state ) &amp; mask;
<a name="l00447"></a>00447     }
<a name="l00448"></a>00448 
<a name="l00449"></a><a class="code" href="namespaceirr_1_1core.html#a894a901069c34298987761c5f3d74f1f">00449</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#a894a901069c34298987761c5f3d74f1f">round_</a>( <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> x )
<a name="l00450"></a>00450     {
<a name="l00451"></a>00451         <span class="keywordflow">return</span> floorf( x + 0.5f );
<a name="l00452"></a>00452     }
<a name="l00453"></a>00453 
<a name="l00454"></a><a class="code" href="namespaceirr_1_1core.html#ab4c17ceae6e2b96383e842eabb9596ab">00454</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <span class="keywordtype">void</span> <a class="code" href="namespaceirr_1_1core.html#ab4c17ceae6e2b96383e842eabb9596ab">clearFPUException</a> ()
<a name="l00455"></a>00455     {
<a name="l00456"></a>00456 <span class="preprocessor">#ifdef IRRLICHT_FAST_MATH</span>
<a name="l00457"></a>00457 <span class="preprocessor"></span>        <span class="keywordflow">return</span>;
<a name="l00458"></a>00458 <span class="preprocessor">#ifdef feclearexcept</span>
<a name="l00459"></a>00459 <span class="preprocessor"></span>        feclearexcept(FE_ALL_EXCEPT);
<a name="l00460"></a>00460 <span class="preprocessor">#elif defined(_MSC_VER)</span>
<a name="l00461"></a>00461 <span class="preprocessor"></span>        __asm fnclex;
<a name="l00462"></a>00462 <span class="preprocessor">#elif defined(__GNUC__) &amp;&amp; defined(__x86__)</span>
<a name="l00463"></a>00463 <span class="preprocessor"></span>        __asm__ __volatile__ (<span class="stringliteral">&quot;fclex \n\t&quot;</span>);
<a name="l00464"></a>00464 <span class="preprocessor">#else</span>
<a name="l00465"></a>00465 <span class="preprocessor"></span><span class="preprocessor">#  warn clearFPUException not supported.</span>
<a name="l00466"></a>00466 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00467"></a>00467 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00468"></a>00468 <span class="preprocessor"></span>    }
<a name="l00469"></a>00469 
<a name="l00470"></a>00470     <span class="comment">// calculate: sqrt ( x )</span>
<a name="l00471"></a><a class="code" href="namespaceirr_1_1core.html#af2f378cc34a19f5da6fe1d4961646d1d">00471</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#af2f378cc34a19f5da6fe1d4961646d1d">squareroot</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> f)
<a name="l00472"></a>00472     {
<a name="l00473"></a>00473         <span class="keywordflow">return</span> sqrtf(f);
<a name="l00474"></a>00474     }
<a name="l00475"></a>00475 
<a name="l00476"></a>00476     <span class="comment">// calculate: sqrt ( x )</span>
<a name="l00477"></a><a class="code" href="namespaceirr_1_1core.html#ad4378f076bf251c05e543ce888da8f48">00477</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> <a class="code" href="namespaceirr_1_1core.html#af2f378cc34a19f5da6fe1d4961646d1d">squareroot</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> f)
<a name="l00478"></a>00478     {
<a name="l00479"></a>00479         <span class="keywordflow">return</span> sqrt(f);
<a name="l00480"></a>00480     }
<a name="l00481"></a>00481 
<a name="l00482"></a>00482     <span class="comment">// calculate: sqrt ( x )</span>
<a name="l00483"></a><a class="code" href="namespaceirr_1_1core.html#a6943186698de9d2ff47ce03fbe025230">00483</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#af2f378cc34a19f5da6fe1d4961646d1d">squareroot</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> f)
<a name="l00484"></a>00484     {
<a name="l00485"></a>00485         <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a><span class="keyword">&gt;</span>(<a class="code" href="namespaceirr_1_1core.html#af2f378cc34a19f5da6fe1d4961646d1d">squareroot</a>(static_cast&lt;f32&gt;(f)));
<a name="l00486"></a>00486     }
<a name="l00487"></a>00487 
<a name="l00488"></a>00488 <span class="preprocessor">#ifdef __IRR_HAS_S64</span>
<a name="l00489"></a>00489 <span class="preprocessor"></span>    <span class="comment">// calculate: sqrt ( x )</span>
<a name="l00490"></a><a class="code" href="namespaceirr_1_1core.html#a9a79fc4c36183e75d70c740b2b9f1865">00490</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#abf54bd535f8d4dd996270e68c3ad8c08" title="64 bit signed variable.">s64</a> <a class="code" href="namespaceirr_1_1core.html#af2f378cc34a19f5da6fe1d4961646d1d">squareroot</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#abf54bd535f8d4dd996270e68c3ad8c08" title="64 bit signed variable.">s64</a> f)
<a name="l00491"></a>00491     {
<a name="l00492"></a>00492         <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><a class="code" href="namespaceirr.html#abf54bd535f8d4dd996270e68c3ad8c08" title="64 bit signed variable.">s64</a><span class="keyword">&gt;</span>(<a class="code" href="namespaceirr_1_1core.html#af2f378cc34a19f5da6fe1d4961646d1d">squareroot</a>(static_cast&lt;f64&gt;(f)));
<a name="l00493"></a>00493     }
<a name="l00494"></a>00494 <span class="preprocessor">#endif</span>
<a name="l00495"></a>00495 <span class="preprocessor"></span>
<a name="l00496"></a>00496     <span class="comment">// calculate: 1 / sqrt ( x )</span>
<a name="l00497"></a><a class="code" href="namespaceirr_1_1core.html#adaef309f12c2a3386e94610e24f2bfa7">00497</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> <a class="code" href="namespaceirr_1_1core.html#adaef309f12c2a3386e94610e24f2bfa7">reciprocal_squareroot</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> x)
<a name="l00498"></a>00498     {
<a name="l00499"></a>00499         <span class="keywordflow">return</span> 1.0 / sqrt(x);
<a name="l00500"></a>00500     }
<a name="l00501"></a>00501 
<a name="l00502"></a>00502     <span class="comment">// calculate: 1 / sqrtf ( x )</span>
<a name="l00503"></a><a class="code" href="namespaceirr_1_1core.html#a42eb747bb19d6ca2cb9d8977eb402c72">00503</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#adaef309f12c2a3386e94610e24f2bfa7">reciprocal_squareroot</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> f)
<a name="l00504"></a>00504     {
<a name="l00505"></a>00505 <span class="preprocessor">#if defined ( IRRLICHT_FAST_MATH )</span>
<a name="l00506"></a>00506 <span class="preprocessor"></span><span class="preprocessor">    #if defined(_MSC_VER)</span>
<a name="l00507"></a>00507 <span class="preprocessor"></span>        <span class="comment">// SSE reciprocal square root estimate, accurate to 12 significant</span>
<a name="l00508"></a>00508         <span class="comment">// bits of the mantissa</span>
<a name="l00509"></a>00509         <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> recsqrt;
<a name="l00510"></a>00510         __asm rsqrtss xmm0, f           <span class="comment">// xmm0 = rsqrtss(f)</span>
<a name="l00511"></a>00511         __asm movss recsqrt, xmm0       <span class="comment">// return xmm0</span>
<a name="l00512"></a>00512         <span class="keywordflow">return</span> recsqrt;
<a name="l00513"></a>00513 
<a name="l00514"></a>00514 <span class="comment">/*</span>
<a name="l00515"></a>00515 <span class="comment">        // comes from Nvidia</span>
<a name="l00516"></a>00516 <span class="comment">        u32 tmp = (u32(IEEE_1_0 &lt;&lt; 1) + IEEE_1_0 - *(u32*)&amp;x) &gt;&gt; 1;</span>
<a name="l00517"></a>00517 <span class="comment">        f32 y = *(f32*)&amp;tmp;</span>
<a name="l00518"></a>00518 <span class="comment">        return y * (1.47f - 0.47f * x * y * y);</span>
<a name="l00519"></a>00519 <span class="comment">*/</span>
<a name="l00520"></a>00520 <span class="preprocessor">    #else</span>
<a name="l00521"></a>00521 <span class="preprocessor"></span>        <span class="keywordflow">return</span> 1.f / sqrtf(f);
<a name="l00522"></a>00522 <span class="preprocessor">    #endif</span>
<a name="l00523"></a>00523 <span class="preprocessor"></span><span class="preprocessor">#else // no fast math</span>
<a name="l00524"></a>00524 <span class="preprocessor"></span>        <span class="keywordflow">return</span> 1.f / sqrtf(f);
<a name="l00525"></a>00525 <span class="preprocessor">#endif</span>
<a name="l00526"></a>00526 <span class="preprocessor"></span>    }
<a name="l00527"></a>00527 
<a name="l00528"></a>00528     <span class="comment">// calculate: 1 / sqrtf( x )</span>
<a name="l00529"></a><a class="code" href="namespaceirr_1_1core.html#a21c37238a7754b48ff18c486202a1e4b">00529</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#adaef309f12c2a3386e94610e24f2bfa7">reciprocal_squareroot</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> x)
<a name="l00530"></a>00530     {
<a name="l00531"></a>00531         <span class="keywordflow">return</span> <span class="keyword">static_cast&lt;</span><a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a><span class="keyword">&gt;</span>(<a class="code" href="namespaceirr_1_1core.html#adaef309f12c2a3386e94610e24f2bfa7">reciprocal_squareroot</a>(static_cast&lt;f32&gt;(x)));
<a name="l00532"></a>00532     }
<a name="l00533"></a>00533 
<a name="l00534"></a>00534     <span class="comment">// calculate: 1 / x</span>
<a name="l00535"></a><a class="code" href="namespaceirr_1_1core.html#aa01390f49052dfe07e16ee6c5233f4eb">00535</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#aa01390f49052dfe07e16ee6c5233f4eb">reciprocal</a>( <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> f )
<a name="l00536"></a>00536     {
<a name="l00537"></a>00537 <span class="preprocessor">#if defined (IRRLICHT_FAST_MATH)</span>
<a name="l00538"></a>00538 <span class="preprocessor"></span>
<a name="l00539"></a>00539         <span class="comment">// SSE Newton-Raphson reciprocal estimate, accurate to 23 significant</span>
<a name="l00540"></a>00540         <span class="comment">// bi ts of the mantissa</span>
<a name="l00541"></a>00541         <span class="comment">// One Newtown-Raphson Iteration:</span>
<a name="l00542"></a>00542         <span class="comment">// f(i+1) = 2 * rcpss(f) - f * rcpss(f) * rcpss(f)</span>
<a name="l00543"></a>00543         <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> rec;
<a name="l00544"></a>00544         __asm rcpss xmm0, f               <span class="comment">// xmm0 = rcpss(f)</span>
<a name="l00545"></a>00545         __asm movss xmm1, f               <span class="comment">// xmm1 = f</span>
<a name="l00546"></a>00546         __asm mulss xmm1, xmm0            <span class="comment">// xmm1 = f * rcpss(f)</span>
<a name="l00547"></a>00547         __asm mulss xmm1, xmm0            <span class="comment">// xmm2 = f * rcpss(f) * rcpss(f)</span>
<a name="l00548"></a>00548         __asm addss xmm0, xmm0            <span class="comment">// xmm0 = 2 * rcpss(f)</span>
<a name="l00549"></a>00549         __asm subss xmm0, xmm1            <span class="comment">// xmm0 = 2 * rcpss(f)</span>
<a name="l00550"></a>00550                                           <span class="comment">//        - f * rcpss(f) * rcpss(f)</span>
<a name="l00551"></a>00551         __asm movss rec, xmm0             <span class="comment">// return xmm0</span>
<a name="l00552"></a>00552         <span class="keywordflow">return</span> rec;
<a name="l00553"></a>00553 
<a name="l00554"></a>00554 
<a name="l00556"></a>00556         <span class="comment">// instead set f to a high value to get a return value near zero..</span>
<a name="l00557"></a>00557         <span class="comment">// -1000000000000.f.. is use minus to stay negative..</span>
<a name="l00558"></a>00558         <span class="comment">// must test&#39;s here (plane.normal dot anything ) checks on &lt;= 0.f</span>
<a name="l00559"></a>00559         <span class="comment">//u32 x = (-(AIR(f) != 0 ) &gt;&gt; 31 ) &amp; ( IR(f) ^ 0xd368d4a5 ) ^ 0xd368d4a5;</span>
<a name="l00560"></a>00560         <span class="comment">//return 1.f / FR ( x );</span>
<a name="l00561"></a>00561 
<a name="l00562"></a>00562 <span class="preprocessor">#else // no fast math</span>
<a name="l00563"></a>00563 <span class="preprocessor"></span>        <span class="keywordflow">return</span> 1.f / f;
<a name="l00564"></a>00564 <span class="preprocessor">#endif</span>
<a name="l00565"></a>00565 <span class="preprocessor"></span>    }
<a name="l00566"></a>00566 
<a name="l00567"></a>00567     <span class="comment">// calculate: 1 / x</span>
<a name="l00568"></a><a class="code" href="namespaceirr_1_1core.html#ac4402e2ec5b151212168736b8cfdd587">00568</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> <a class="code" href="namespaceirr_1_1core.html#aa01390f49052dfe07e16ee6c5233f4eb">reciprocal</a> ( <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a1325b02603ad449f92c68fc640af9b28" title="64 bit floating point variable.">f64</a> f )
<a name="l00569"></a>00569     {
<a name="l00570"></a>00570         <span class="keywordflow">return</span> 1.0 / f;
<a name="l00571"></a>00571     }
<a name="l00572"></a>00572 
<a name="l00573"></a>00573 
<a name="l00574"></a>00574     <span class="comment">// calculate: 1 / x, low precision allowed</span>
<a name="l00575"></a><a class="code" href="namespaceirr_1_1core.html#ab5de17006aac4618e43d5f816ffc97c9">00575</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#ab5de17006aac4618e43d5f816ffc97c9">reciprocal_approxim</a> ( <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> f )
<a name="l00576"></a>00576     {
<a name="l00577"></a>00577 <span class="preprocessor">#if defined( IRRLICHT_FAST_MATH)</span>
<a name="l00578"></a>00578 <span class="preprocessor"></span>
<a name="l00579"></a>00579         <span class="comment">// SSE Newton-Raphson reciprocal estimate, accurate to 23 significant</span>
<a name="l00580"></a>00580         <span class="comment">// bi ts of the mantissa</span>
<a name="l00581"></a>00581         <span class="comment">// One Newtown-Raphson Iteration:</span>
<a name="l00582"></a>00582         <span class="comment">// f(i+1) = 2 * rcpss(f) - f * rcpss(f) * rcpss(f)</span>
<a name="l00583"></a>00583         <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> rec;
<a name="l00584"></a>00584         __asm rcpss xmm0, f               <span class="comment">// xmm0 = rcpss(f)</span>
<a name="l00585"></a>00585         __asm movss xmm1, f               <span class="comment">// xmm1 = f</span>
<a name="l00586"></a>00586         __asm mulss xmm1, xmm0            <span class="comment">// xmm1 = f * rcpss(f)</span>
<a name="l00587"></a>00587         __asm mulss xmm1, xmm0            <span class="comment">// xmm2 = f * rcpss(f) * rcpss(f)</span>
<a name="l00588"></a>00588         __asm addss xmm0, xmm0            <span class="comment">// xmm0 = 2 * rcpss(f)</span>
<a name="l00589"></a>00589         __asm subss xmm0, xmm1            <span class="comment">// xmm0 = 2 * rcpss(f)</span>
<a name="l00590"></a>00590                                           <span class="comment">//        - f * rcpss(f) * rcpss(f)</span>
<a name="l00591"></a>00591         __asm movss rec, xmm0             <span class="comment">// return xmm0</span>
<a name="l00592"></a>00592         <span class="keywordflow">return</span> rec;
<a name="l00593"></a>00593 
<a name="l00594"></a>00594 
<a name="l00595"></a>00595 <span class="comment">/*</span>
<a name="l00596"></a>00596 <span class="comment">        // SSE reciprocal estimate, accurate to 12 significant bits of</span>
<a name="l00597"></a>00597 <span class="comment">        f32 rec;</span>
<a name="l00598"></a>00598 <span class="comment">        __asm rcpss xmm0, f             // xmm0 = rcpss(f)</span>
<a name="l00599"></a>00599 <span class="comment">        __asm movss rec , xmm0          // return xmm0</span>
<a name="l00600"></a>00600 <span class="comment">        return rec;</span>
<a name="l00601"></a>00601 <span class="comment">*/</span>
<a name="l00602"></a>00602 <span class="comment">/*</span>
<a name="l00603"></a>00603 <span class="comment">        register u32 x = 0x7F000000 - IR ( p );</span>
<a name="l00604"></a>00604 <span class="comment">        const f32 r = FR ( x );</span>
<a name="l00605"></a>00605 <span class="comment">        return r * (2.0f - p * r);</span>
<a name="l00606"></a>00606 <span class="comment">*/</span>
<a name="l00607"></a>00607 <span class="preprocessor">#else // no fast math</span>
<a name="l00608"></a>00608 <span class="preprocessor"></span>        <span class="keywordflow">return</span> 1.f / f;
<a name="l00609"></a>00609 <span class="preprocessor">#endif</span>
<a name="l00610"></a>00610 <span class="preprocessor"></span>    }
<a name="l00611"></a>00611 
<a name="l00612"></a>00612 
<a name="l00613"></a><a class="code" href="namespaceirr_1_1core.html#ac230a392b15e3d27c6e2a07a6925a8c4">00613</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#ac230a392b15e3d27c6e2a07a6925a8c4">floor32</a>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> x)
<a name="l00614"></a>00614     {
<a name="l00615"></a>00615 <span class="preprocessor">#ifdef IRRLICHT_FAST_MATH</span>
<a name="l00616"></a>00616 <span class="preprocessor"></span>        <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> h = 0.5f;
<a name="l00617"></a>00617 
<a name="l00618"></a>00618         <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> t;
<a name="l00619"></a>00619 
<a name="l00620"></a>00620 <span class="preprocessor">#if defined(_MSC_VER)</span>
<a name="l00621"></a>00621 <span class="preprocessor"></span>        __asm
<a name="l00622"></a>00622         {
<a name="l00623"></a>00623             fld x
<a name="l00624"></a>00624             fsub    h
<a name="l00625"></a>00625             fistp   t
<a name="l00626"></a>00626         }
<a name="l00627"></a>00627 <span class="preprocessor">#elif defined(__GNUC__)</span>
<a name="l00628"></a>00628 <span class="preprocessor"></span>        __asm__ __volatile__ (
<a name="l00629"></a>00629             <span class="stringliteral">&quot;fsub %2 \n\t&quot;</span>
<a name="l00630"></a>00630             <span class="stringliteral">&quot;fistpl %0&quot;</span>
<a name="l00631"></a>00631             : <span class="stringliteral">&quot;=m&quot;</span> (t)
<a name="l00632"></a>00632             : <span class="stringliteral">&quot;t&quot;</span> (x), <span class="stringliteral">&quot;f&quot;</span> (h)
<a name="l00633"></a>00633             : <span class="stringliteral">&quot;st&quot;</span>
<a name="l00634"></a>00634             );
<a name="l00635"></a>00635 <span class="preprocessor">#else</span>
<a name="l00636"></a>00636 <span class="preprocessor"></span><span class="preprocessor">#  warn IRRLICHT_FAST_MATH not supported.</span>
<a name="l00637"></a>00637 <span class="preprocessor"></span>        <span class="keywordflow">return</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>) floorf ( x );
<a name="l00638"></a>00638 <span class="preprocessor">#endif</span>
<a name="l00639"></a>00639 <span class="preprocessor"></span>        <span class="keywordflow">return</span> t;
<a name="l00640"></a>00640 <span class="preprocessor">#else // no fast math</span>
<a name="l00641"></a>00641 <span class="preprocessor"></span>        <span class="keywordflow">return</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>) floorf ( x );
<a name="l00642"></a>00642 <span class="preprocessor">#endif</span>
<a name="l00643"></a>00643 <span class="preprocessor"></span>    }
<a name="l00644"></a>00644 
<a name="l00645"></a>00645 
<a name="l00646"></a><a class="code" href="namespaceirr_1_1core.html#a0fb8b4d0f177af411fdd4bd94b6779ce">00646</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#a0fb8b4d0f177af411fdd4bd94b6779ce">ceil32</a> ( <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> x )
<a name="l00647"></a>00647     {
<a name="l00648"></a>00648 <span class="preprocessor">#ifdef IRRLICHT_FAST_MATH</span>
<a name="l00649"></a>00649 <span class="preprocessor"></span>        <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> h = 0.5f;
<a name="l00650"></a>00650 
<a name="l00651"></a>00651         <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> t;
<a name="l00652"></a>00652 
<a name="l00653"></a>00653 <span class="preprocessor">#if defined(_MSC_VER)</span>
<a name="l00654"></a>00654 <span class="preprocessor"></span>        __asm
<a name="l00655"></a>00655         {
<a name="l00656"></a>00656             fld x
<a name="l00657"></a>00657             fadd    h
<a name="l00658"></a>00658             fistp   t
<a name="l00659"></a>00659         }
<a name="l00660"></a>00660 <span class="preprocessor">#elif defined(__GNUC__)</span>
<a name="l00661"></a>00661 <span class="preprocessor"></span>        __asm__ __volatile__ (
<a name="l00662"></a>00662             <span class="stringliteral">&quot;fadd %2 \n\t&quot;</span>
<a name="l00663"></a>00663             <span class="stringliteral">&quot;fistpl %0 \n\t&quot;</span>
<a name="l00664"></a>00664             : <span class="stringliteral">&quot;=m&quot;</span>(t)
<a name="l00665"></a>00665             : <span class="stringliteral">&quot;t&quot;</span>(x), <span class="stringliteral">&quot;f&quot;</span>(h)
<a name="l00666"></a>00666             : <span class="stringliteral">&quot;st&quot;</span>
<a name="l00667"></a>00667             );
<a name="l00668"></a>00668 <span class="preprocessor">#else</span>
<a name="l00669"></a>00669 <span class="preprocessor"></span><span class="preprocessor">#  warn IRRLICHT_FAST_MATH not supported.</span>
<a name="l00670"></a>00670 <span class="preprocessor"></span>        <span class="keywordflow">return</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>) ceilf ( x );
<a name="l00671"></a>00671 <span class="preprocessor">#endif</span>
<a name="l00672"></a>00672 <span class="preprocessor"></span>        <span class="keywordflow">return</span> t;
<a name="l00673"></a>00673 <span class="preprocessor">#else // not fast math</span>
<a name="l00674"></a>00674 <span class="preprocessor"></span>        <span class="keywordflow">return</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>) ceilf ( x );
<a name="l00675"></a>00675 <span class="preprocessor">#endif</span>
<a name="l00676"></a>00676 <span class="preprocessor"></span>    }
<a name="l00677"></a>00677 
<a name="l00678"></a>00678 
<a name="l00679"></a>00679 
<a name="l00680"></a><a class="code" href="namespaceirr_1_1core.html#ae46f57f03e9033c57c180fbe83b04cf2">00680</a>     <a class="code" href="irr_math_8h.html#a3695e51e0a187a6c49684ba3206b0d0a">REALINLINE</a> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#ae46f57f03e9033c57c180fbe83b04cf2">round32</a>(<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> x)
<a name="l00681"></a>00681     {
<a name="l00682"></a>00682 <span class="preprocessor">#if defined(IRRLICHT_FAST_MATH)</span>
<a name="l00683"></a>00683 <span class="preprocessor"></span>        <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> t;
<a name="l00684"></a>00684 
<a name="l00685"></a>00685 <span class="preprocessor">#if defined(_MSC_VER)</span>
<a name="l00686"></a>00686 <span class="preprocessor"></span>        __asm
<a name="l00687"></a>00687         {
<a name="l00688"></a>00688             fld   x
<a name="l00689"></a>00689             fistp t
<a name="l00690"></a>00690         }
<a name="l00691"></a>00691 <span class="preprocessor">#elif defined(__GNUC__)</span>
<a name="l00692"></a>00692 <span class="preprocessor"></span>        __asm__ __volatile__ (
<a name="l00693"></a>00693             <span class="stringliteral">&quot;fistpl %0 \n\t&quot;</span>
<a name="l00694"></a>00694             : <span class="stringliteral">&quot;=m&quot;</span>(t)
<a name="l00695"></a>00695             : <span class="stringliteral">&quot;t&quot;</span>(x)
<a name="l00696"></a>00696             : <span class="stringliteral">&quot;st&quot;</span>
<a name="l00697"></a>00697             );
<a name="l00698"></a>00698 <span class="preprocessor">#else</span>
<a name="l00699"></a>00699 <span class="preprocessor"></span><span class="preprocessor">#  warn IRRLICHT_FAST_MATH not supported.</span>
<a name="l00700"></a>00700 <span class="preprocessor"></span>        <span class="keywordflow">return</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>) <a class="code" href="namespaceirr_1_1core.html#a894a901069c34298987761c5f3d74f1f">round_</a>(x);
<a name="l00701"></a>00701 <span class="preprocessor">#endif</span>
<a name="l00702"></a>00702 <span class="preprocessor"></span>        <span class="keywordflow">return</span> t;
<a name="l00703"></a>00703 <span class="preprocessor">#else // no fast math</span>
<a name="l00704"></a>00704 <span class="preprocessor"></span>        <span class="keywordflow">return</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>) <a class="code" href="namespaceirr_1_1core.html#a894a901069c34298987761c5f3d74f1f">round_</a>(x);
<a name="l00705"></a>00705 <span class="preprocessor">#endif</span>
<a name="l00706"></a>00706 <span class="preprocessor"></span>    }
<a name="l00707"></a>00707 
<a name="l00708"></a><a class="code" href="namespaceirr_1_1core.html#a944684da42c3118ebe85ec9c3f77c331">00708</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#a944684da42c3118ebe85ec9c3f77c331">f32_max3</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> b, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> c)
<a name="l00709"></a>00709     {
<a name="l00710"></a>00710         <span class="keywordflow">return</span> a &gt; b ? (a &gt; c ? a : c) : (b &gt; c ? b : c);
<a name="l00711"></a>00711     }
<a name="l00712"></a>00712 
<a name="l00713"></a><a class="code" href="namespaceirr_1_1core.html#a8d7bec533c867b22d0e870236ecf4bad">00713</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#a8d7bec533c867b22d0e870236ecf4bad">f32_min3</a>(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> a, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> b, <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> c)
<a name="l00714"></a>00714     {
<a name="l00715"></a>00715         <span class="keywordflow">return</span> a &lt; b ? (a &lt; c ? a : c) : (b &lt; c ? b : c);
<a name="l00716"></a>00716     }
<a name="l00717"></a>00717 
<a name="l00718"></a><a class="code" href="namespaceirr_1_1core.html#adf530866e57502da85e6a1f0c23932a2">00718</a>     <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> <a class="code" href="namespaceirr_1_1core.html#adf530866e57502da85e6a1f0c23932a2">fract</a> ( <a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a> x )
<a name="l00719"></a>00719     {
<a name="l00720"></a>00720         <span class="keywordflow">return</span> x - floorf ( x );
<a name="l00721"></a>00721     }
<a name="l00722"></a>00722 
<a name="l00723"></a>00723 } <span class="comment">// end namespace core</span>
<a name="l00724"></a>00724 } <span class="comment">// end namespace irr</span>
<a name="l00725"></a>00725 
<a name="l00726"></a>00726 <span class="preprocessor">#ifndef IRRLICHT_FAST_MATH</span>
<a name="l00727"></a>00727 <span class="preprocessor"></span>    <span class="keyword">using</span> <a class="code" href="namespaceirr_1_1core.html#aff42ea2c4d80cb7b45b71d1f63c6a226">irr::core::IR</a>;
<a name="l00728"></a>00728     <span class="keyword">using</span> <a class="code" href="namespaceirr_1_1core.html#ae0940bd4032e5f10cf83b460f73571a3" title="Floating-point representation of an integer value.">irr::core::FR</a>;
<a name="l00729"></a>00729 <span class="preprocessor">#endif</span>
<a name="l00730"></a>00730 <span class="preprocessor"></span>
<a name="l00731"></a>00731 <span class="preprocessor">#endif</span>
<a name="l00732"></a>00732 <span class="preprocessor"></span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="irr_math_8h.html">irrMath.h</a>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht 
Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Sat Jul 9 2016 18:18:19 for Irrlicht 3D Engine by
<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
